function [bv, sebv] = statBootMinRec( y, X, I, lbI, Nsim, blockSize )



%% estimates in the original sample
bv = robustOLS(y,X,0,0); 

T = size(y,1);
N = size(X,2); 

%% run simulations
mat_bvBoot = NaN(Nsim,N);

rng(12345); %set seed to get same results every time

for s=1:Nsim

    numI = 0;

    while numI < lbI;    
    idxBoot = zeros(T,1);

        %find bootstrap indexes in blocks
        idxBoot(1) = ceil(T*rand);
        for t=2:T;

            if rand < (1/blockSize)
            idxBoot(t) = ceil(T*rand);
            else
            idxBoot(t) = idxBoot(t-1) + 1;
                if idxBoot(t)>T
                idxBoot(t)=idxBoot(t)-T;
                end;
            end

        end

    IBoot = I(idxBoot,:);
    
    numI = sum(IBoot);
    
    end
    
    %find bootstrap data
    yBoot = y(idxBoot,:);
    XBoot = X(idxBoot,:);
    
    %reestimate regression
    [bvBoot, ~, ~] = robustOLS(yBoot, XBoot, 0, 0);
     
    mat_bvBoot(s,:) = bvBoot';
         

end

%% Collect outputs

sebv = std(mat_bvBoot,1)';


end